/************************************************************************
  * Copyright(c) 2023 Levetop Semiconductor Co.,Led. All rights reserved.
  * @file     tp_rtp.h
  * @author   UartTFT Application Team
  * @version  V0.0.1
  * @date     2023-01-01
  * @brief     
 *************************************************************************/

#ifndef _TP_RTP_H
#define _TP_RTP_H

#include "data.h"

/*-------------------------------------------RTP GPIO ------------------------------*/
//   XM = X-    int07/ain7                 Y-
//   XP = X+    int05/ain5             X-      X+
//   YM = Y-    int06/ain6                 Y+
//   YP = Y+    int04/ain4
#if (LT_TOUCH_FLAG == 1)
#define RTP_XM_OUT		 EPORT0->EPDDR |= (1<<7)  // X- configure as GPIO output
#define RTP_XM_IN	 	 EPORT0->EPDDR &=~(1<<7)  // X- configure as GPIO input
#define RTP_XM_UP		 EPORT0->EPPUE |= (1<<7)  // X- configured as pull-up
#define RTP_XM_DOWN		 EPORT0->EPPUE &=~(1<<7)  // X- configure as pull-down
#define RTP_XM_LEVEL(x)	 (x==0)?(EPORT0->EPDR &=~(1<<7)):(EPORT0->EPDR |= (1<<7))  // X- output high or low level

#define RTP_XP_OUT		 EPORT0->EPDDR |= (1<<5)
#define RTP_XP_IN		 EPORT0->EPDDR &=~(1<<5)
#define RTP_XP_UP		 EPORT0->EPPUE |= (1<<5)
#define RTP_XP_DOWN		 EPORT0->EPPUE &=~(1<<5)
#define RTP_XP_LEVEL(x)  (x==0)?(EPORT0->EPDR &=~(1<<5)):(EPORT0->EPDR |= (1<<5))

#define RTP_YM_OUT 		 EPORT0->EPDDR |= (1<<6)
#define RTP_YM_IN 		 EPORT0->EPDDR &=~(1<<6)
#define RTP_YM_UP 		 EPORT0->EPPUE |= (1<<6)
#define RTP_YM_DOWN		 EPORT0->EPPUE &=~(1<<6)
#define RTP_YM_LEVEL(x)  (x==0)?(EPORT0->EPDR &=~(1<<6)):(EPORT0->EPDR |= (1<<6))

#define RTP_YP_OUT 		 EPORT0->EPDDR |= (1<<4)
#define RTP_YP_IN 		 EPORT0->EPDDR &=~(1<<4)
#define RTP_YP_UP 		 EPORT0->EPPUE |= (1<<4)
#define RTP_YP_DOWN 	 EPORT0->EPPUE &=~(1<<4)
#define RTP_YP_LEVEL(x)  (x==0)?(EPORT0->EPDR &=~(1<<4)):(EPORT0->EPDR |= (1<<4))
#endif

uint8_t LT_TpInit(void);
uint8_t LT_TpScan(void);
uint8_t LT_TpAdjust(void);
void LT_TpSaveAdjdata(void);
uint8_t LT_TpGetAdjdata(void);
uint8_t TP_Read_XY2(uint16_t *x, uint16_t *y);

#endif /* _TP_RTP_H */
